/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "user_token")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UserToken.findAll", query = "SELECT u FROM UserToken u"),
    @NamedQuery(name = "UserToken.findByIdUserToken", query = "SELECT u FROM UserToken u WHERE u.idUserToken = :idUserToken"),
    @NamedQuery(name = "UserToken.findByUser", query = "SELECT u FROM UserToken u WHERE u.user.idUser = :idUser"),
    @NamedQuery(name = "UserToken.findByToken", query = "SELECT u FROM UserToken u WHERE u.token = :token"),
    @NamedQuery(name = "UserToken.findByCreationDate", query = "SELECT u FROM UserToken u WHERE u.creationDate = :creationDate")})
public class UserToken implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_USER_TOKEN")
    private Integer idUserToken;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "TOKEN")
    private String token;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CREATION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;
    @JoinColumn(name = "USER", referencedColumnName = "ID_USER")
    @ManyToOne(optional = false)
    private User user;

    public UserToken() {
    }

    public UserToken(Integer idUserToken) {
        this.idUserToken = idUserToken;
    }

    public UserToken(Integer idUserToken, String token, Date creationDate) {
        this.idUserToken = idUserToken;
        this.token = token;
        this.creationDate = creationDate;
    }

    public Integer getIdUserToken() {
        return idUserToken;
    }

    public void setIdUserToken(Integer idUserToken) {
        this.idUserToken = idUserToken;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idUserToken != null ? idUserToken.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UserToken)) {
            return false;
        }
        UserToken other = (UserToken) object;
        if ((this.idUserToken == null && other.idUserToken != null) || (this.idUserToken != null && !this.idUserToken.equals(other.idUserToken))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.UserToken[ idUserToken=" + idUserToken + " ]";
    }
    
}
